<template>
  <el-form :inline="true" @submit.native.prevent>
    <el-form-item>
      <el-input v-model="queryParam.keyword"
                @keyup.enter="handleQuery"
                placeholder="输入手机号/卡号"
                type="text"
                prefix-icon="search"
                auto-complete="off"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleQuery">搜索</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="tableData.list" v-loading="loading" border height="calc(100vh - 210px)">
    <el-table-column label="卡号" prop="ucard" width="150" align="center"/>
    <el-table-column label="手机号" prop="phone" width="120" align="center"/>
    <el-table-column label="姓名" prop="username" width="110" align="center"/>
    <el-table-column label="性别" prop="sex" width="60" align="center" :formatter="Dic.sexType"/>
    <el-table-column label="首次消费" prop="shopName" width="140" align="center"/>
    <el-table-column label="型号" prop="phoneSkuName" width="90" align="center"/>
    <el-table-column label="类型" prop="isHy" width="80" align="center" :formatter="Dic.memberType"/>
    <el-table-column label="积分" prop="upoints" min-width="80" align="center"/>
    <el-table-column label="余额" prop="wuprice" min-width="80" :formatter="Dic.Price" align="center"/>
    <el-table-column label="累计消费" prop="xiaofei" width="100" :formatter="Dic.Price" align="center"/>
    <el-table-column label="消费次数" prop="orderTotal" width="60" align="center"/>
    <el-table-column label="一年内消费次数" prop="orderYearTotal" width="90" align="center"/>
    <el-table-column label="操作" width="80" align="center" fixed="right">
      <template v-slot="{row}">
        <el-button link type="primary" @click="openRow(row)">
          查看
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination layout="->,total,sizes,prev,pager,next,jumper"
                 v-model:current-page="queryParam.page"
                 v-model:page-size="queryParam.limit"
                 :total="tableData.total" background
                 @current-change="loadList"
                 @size-change="loadList"/>
  <member-list-detail v-model="openRowDialog"
                      :info="currentRow"
                      :close="()=>{this.openRowDialog = false}"/>
</template>

<script lang="ts">
import memberApi from "@/api/member";
import memberListDetail from "@/components/member/memberListDetail.vue";
import Dic from "@/utils/dic"

export default {
  name: "memberList",
  components: {memberListDetail},
  data() {
    return {
      Dic,
      queryParam: {
        page: 1,
        limit: 20,
        keyword: "",
        byLan: true,
      },
      tableData: {
        list: [],
        total: 0,
      },
      openRowDialog: false,
      currentRow: {},
      loading: false,
    };
  },
  created() {
    this.loadList();
  },
  methods: {
    handleQuery() {
      this.queryParam.page = 1;
      this.loadList();
    },
    loadList() {
      this.loading = true
      memberApi.listAndStatistics(this.queryParam).then(res => {
        this.loading = false
        this.tableData = res.data
      })
    },
    openRow(row) {
      this.openRowDialog = true;
      this.currentRow = row
    }
  }
}
</script>
<style lang="scss" scoped>

</style>